package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 经销商来源
 *
 * @author xinpeng.jiang
 * @version 1.0
 * @date 2020/12/21 19:46
 * @since V1.0
 */
@Getter
public enum GradeEnum {
    // 优良
    EXCELLENT("0", "enum.grade.name.excellent"),
    // 一般
    GENERAL("1", "enum.grade.name.general"),
    // 较差
    POOR("2", "enum.grade.name.poor"),
    ;

    private String code;
    private String name;

    GradeEnum(String code, String name) {
        this.name = name;
        this.code = code;
    }

    /**
     * 获取全部枚举
     *
     * @return List<PhoneExtEnum>
     */
    public static List<GradeEnum> getAllEnum() {
        List<GradeEnum> list = new ArrayList<>();
        for (GradeEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    /**
     * 根据code获取枚举
     *
     * @return
     */
    public static GradeEnum getByCode(String code) {
        for (GradeEnum cache : values()) {
            if (Objects.equals(code, cache.getCode())) {
                return cache;
            }
        }
        return null;
    }

    /**
     * 通过code获取联系方式解释名
     *
     * @param code
     * @return java.lang.String
     * @author zcp
     * @date 2019/7/3 22:03
     * @version v1.0
     * @since v1.0
     */
    public static String getNameByCode(String code) {
        for (GradeEnum cache : values()) {
            if (Objects.equals(code, cache.getCode())) {
                return cache.getName();
            }
        }
        return null;
    }

    /**
     * 通过联系方式解释名获取code
     *
     * @param name
     * @return java.lang.String
     * @author zcp
     * @date 2019/7/3 22:03
     * @version v1.0
     * @since v1.0
     */
    public static String getCodeByName(String name) {
        for (GradeEnum cache : values()) {
            if (Objects.equals(name, cache.getName())) {
                return cache.code;
            }
        }
        return null;
    }


    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
